<?php

class Student_Model_DbTable_guestGPA extends Zend_Db_Table_Abstract
{
    

    public function gpaCalc($gr1, $cr1, $gr2, $cr2, $gr3, $cr3, $gr4, $cr4, $gr5, $cr5, $gr6, $cr6, $gr7, $cr7, $gr8, $cr8){
       
        $inGrade[0] = $gr1;
        $inGrade[1] = $gr2;
        $inGrade[2] = $gr3;
        $inGrade[3] = $gr4;
        $inGrade[4] = $gr5;
        $inGrade[5] = $gr6;
        $inGrade[6] = $gr7;
        $inGrade[7] = $gr8;

        $inCredits[0] = $cr1;
        $inCredits[1] = $cr2;
        $inCredits[2] = $cr3;
        $inCredits[3] = $cr4;
        $inCredits[4] = $cr5;
        $inCredits[5] = $cr6;
        $inCredits[6] = $cr7;
        $inCredits[7] = $cr8;

        $allgr = 0;
        $allcr = 0;
        $GPA = 0;
        $equiv = 0;
        $total = 0.0;
        $total_credits = 0.0;


        for($i=0; $i<8;$i++){
        if(!$inGrade[$i]== null)
        {
            if($inGrade[$i] == 'A'){
                $equiv = 4.0;
                $total += $equiv * ($inCredits[$i]);
                $total_credits += $inCredits[$i];

            }
            if ($inGrade[$i] == 'A-'){
                $equiv = 3.67;
                $total += $equiv * ($inCredits[$i]);
                $total_credits += $inCredits[$i];


            }
            if ($inGrade[$i] == 'B+'){
                $equiv = 3.33;
                $total += $equiv * ($inCredits[$i]);
                $total_credits += $inCredits[$i];


            }
            if ($inGrade[$i] == 'B'){
                $equiv = 3.00;
                $total += $equiv * ($inCredits[$i]);
                $total_credits += $inCredits[$i];


            }
            if ($inGrade[$i] == 'B-'){
                $equiv = 2.67;
                $total += $equiv * ($inCredits[$i]);
                $total_credits += $inCredits[$i];


            }
            if ($inGrade[$i] == 'C+'){
                $equiv = 2.33;
                $total += $equiv * ($inCredits[$i]);
                $total_credits += $inCredits[$i];


            }
            if ($inGrade[$i] == 'C'){
                $equiv = 2.00;
                $total += $equiv * ($inCredits[$i]);
                $total_credits += $inCredits[$i];


            }
            if ($inGrade[$i] == 'C-'){
                $equiv = 1.67;
                $total += $equiv * ($inCredits[$i]);
                $total_credits += $inCredits[$i];


            }
            if ($inGrade[$i] == 'D+'){
                $equiv = 1.33;
                $total += $equiv * ($inCredits[$i]);
                $total_credits += $inCredits[$i];


            }
            if ($inGrade[$i] == 'D'){
                $equiv = 1.00;
                $total += $equiv * ($inCredits[$i]);
                $total_credits += $inCredits[$i];


            }
            if ($inGrade[$i] == 'D-'){
                $equiv = 0.67;
                $total += $equiv * ($inCredits[$i]);
                $total_credits += $inCredits[$i];


            }
            if ($inGrade[$i]== 'F'){
                $equiv = 0.00;
                $total += $equiv * ($inCredits[$i]);
                $total_credits += $inCredits[$i];


            }
            }

        }

        if(!$total_credits <= 0){
        $GPA = round($total/$total_credits, 2);
        }

        return $GPA;

        }

        //this function is invoked by the gpa model
        public function currentGPA($gradeArray, $creditsArray){

            $total = 0;
            $total_credits = 0.0;
            $equiv = 0;
            $GPA = 0;
            
            for($i=0;$i<=count($gradeArray)-1;$i++){

                if($gradeArray[$i] == 'A'){
                    $equiv = 4.0;
                    $total += $equiv * ($creditsArray[$i]);
                    $total_credits += $creditsArray[$i];
                }

                if ($gradeArray[$i] == 'A-'){
                $equiv = 3.67;
                $total += $equiv * ($creditsArray[$i]);
                $total_credits += $creditsArray[$i];


            }
            if ($gradeArray[$i] == 'B+'){
                $equiv = 3.33;
                $total += $equiv * ($creditsArray[$i]);
                $total_credits += $creditsArray[$i];


            }
            if ($gradeArray[$i] == 'B'){
                $equiv = 3.00;
                $total += $equiv * ($creditsArray[$i]);
                $total_credits += $creditsArray[$i];


            }
            if ($gradeArray[$i] == 'B-'){
                $equiv = 2.67;
                $total += $equiv * ($creditsArray[$i]);
                $total_credits += $creditsArray[$i];


            }
            if ($gradeArray[$i] == 'C+'){
                $equiv = 2.33;
                $total += $equiv * ($creditsArray[$i]);
                $total_credits += $creditsArray[$i];


            }
            if ($gradeArray[$i] == 'C'){
                $equiv = 2.00;
                $total += $equiv * ($creditsArray[$i]);
                $total_credits += $creditsArray[$i];


            }
            if ($gradeArray[$i] == 'C-'){
                $equiv = 1.67;
                $total += $equiv * ($creditsArray[$i]);
                $total_credits += $creditsArray[$i];


            }
            if ($gradeArray[$i] == 'D+'){
                $equiv = 1.33;
                $total += $equiv * ($creditsArray[$i]);
                $total_credits += $creditsArray[$i];


            }
            if ($gradeArray[$i] == 'D'){
                $equiv = 1.00;
                $total += $equiv * ($creditsArray[$i]);
                $total_credits += $creditsArray[$i];


            }
            if ($gradeArray[$i] == 'D-'){
                $equiv = 0.67;
                $total += $equiv * ($creditsArray[$i]);
                $total_credits += $creditsArray[$i];


            }
            if ($gradeArray[$i]== 'F'){
                $equiv = 0.00;
                $total += $equiv * ($creditsArray[$i]);
                $total_credits += $creditsArray[$i];

            }
            }

            if (!$total_credits <= 0){
            $GPA = round($total/$total_credits, 2);
            }

             $retuner=null;
            if (!$GPA <= 0){
                $returner = "Based on provided grades, your current GPA is $GPA";
            }
            else{
                $returner = "GPA unavailable for this semester.";
            }

            return $returner;

        }
}


